// pages/orderDetails/orderDetails.js
var app = getApp(),
  fn = app.fn;
Page({
  addressPhone: "",
  data: {
    moeny: 0,
    ordeDetails: []
  },
  bindPhone: function(e) {
    this.setData({
      addressPhone: e.detail.value
    })
  },

  bindCoupon: function(e) {
    var url;
    var that = this;

    fn.apiData({
      url: 'order.php',
      data: {
        act: 'back_order',
        back_type: '4',
        order_id: that.data.pid,
        back_reason: that.data.addressPhone,
        user_id: app.globalData.uid,
      },
      success: function(res) {
        if (res.data.code == 0) {
          that.setData({
            'ordeDetails': res.data.data
          });

          url = '../refundList/refundList';
          wx.navigateTo({
            url: url
          })

          wx.hideToast();
        }
      }
    });


  },

  onLoad: function(options) {


    var that = this;
    that.setData({
      pid: options.id,
    })


    this.getInitData(options.id)
  },

  checkboxChange: function(e) {

    var that = this;
    var money = 0;



    var index = parseInt(e.currentTarget.dataset.index);
    var value = that.data.ordeDetails.goods_list[index].goods_price;
    value = parseFloat(value);


    if (e.detail.value == '') {

      that.data.moeny = that.data.moeny - value;

    } else {

      that.data.moeny += value;

    }

    that.setData({
      moeny: that.data.moeny,
    })


  },



  getInitData: function(callBack) {
    var that = this;


    fn.apiData({
      url: 'order.php',
      data: {
        order_id: callBack,
        act: 'order_detail',
        user_id: app.globalData.uid,
      },
      success: function(res) {
        if (res.data.code == 0) {
          that.setData({
            'ordeDetails': res.data.data
          });

          wx.hideToast();
        }
      }
    });
  }
})